//
//  ZZSearchBar.swift
//  sina
//
//  Created by 张鹏 on 16/5/20.
//  Copyright © 2016年 ZP. All rights reserved.
//

import UIKit

class ZZDiscoverSearchView: UIView {

   
    @IBOutlet weak var textView: UITextField!

    @IBOutlet weak var rightBtn: UIButton!

    //右边的约束对象
    @IBOutlet weak var rightCons: NSLayoutConstraint!


    //设置textView
    override func awakeFromNib() {
        
        
        self.frame = CGRectMake(0, 0,UIScreen.mainScreen().bounds.width , self.bounds.height)
        
        self.textView.leftView = UIImageView(image: UIImage(named: "searchbar_textfield_search_icon"))
        
        self.textView.leftView?.frame = CGRectMake(0, 0, 60, self.bounds.height)
        
        //设置图片的位置
        self.textView.leftView?.contentMode = .Center
        

        //liftView的显示为总是显示
        self.textView.leftViewMode = .Always
        
        //设置圆角
        textView.layer.cornerRadius = 10
        textView.layer.masksToBounds = true
        //设置边线的颜色
        textView.layer.borderColor = UIColor.orangeColor().CGColor
        textView.layer.borderWidth = 2
        
    }
   
    //class 类方法
    //加载xib
    class func loadSearchView() -> ZZDiscoverSearchView {
    
        let v = NSBundle.mainBundle().loadNibNamed("ZZDiscoverSearchView", owner: nil, options: nil).last as! ZZDiscoverSearchView
      
        return v
    
    }

 
    @IBAction func textTF(sender: AnyObject) {
 
        //开启动画
        UIView.animateWithDuration(0.25) { 
            
           self.rightCons.constant = self.rightBtn.frame.width
            //强制刷新
            self.layoutIfNeeded()
        }
  
    }

    
    @IBAction func rigntBtnDidClick(sender: AnyObject) {
        
        //取消键盘的第一响应者
        self.endEditing(true)
        
        rightCons.constant = 0
        
        //动画
        UIView.animateWithDuration(0.25) { 
            
            self.layoutIfNeeded()
        }
    }

}
